﻿using System;
using System.Data;
using BLL;
using CrystalDecisions.CrystalReports.Engine;

public partial class ViewTest_OutputTestItem : System.Web.UI.Page
{
    private ReportDocument doc = new ReportDocument();

    private string ProductSN
    {
        get { return Session["productSN"].ToString(); }
    }

    private string UserID
    {
        get { return Session["UserID"].ToString(); }
    }

    private DateTime TestTime
    {
        get { return DateTime.Parse(Session["testTime"].ToString()); }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //显示报表总页数
            this.CrystalReportViewer1.ShowLastPage();
            this.CrystalReportViewer1.ShowFirstPage();
            this.Page.Unload += new EventHandler(Page_Unload);
        }
    }
    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {
        ForCrystalReport();
    }

    protected void ForCrystalReport()
    {
        doc.Load(Server.MapPath("~/ViewTest/CrystalReportforProductType/ARH9E_Single.rpt"));
        //doc = new CrystalReport1();

        TextObject txtProductSN = (TextObject)doc.ReportDefinition.ReportObjects["Text214"];
        txtProductSN.Text = this.ProductSN;
        TextObject txtUserID = (TextObject)doc.ReportDefinition.ReportObjects["Text215"];
        txtUserID.Text = this.UserID;
        DataSet list = GetData();
        doc.SetDataSource(list.Tables[0]);
        this.CrystalReportViewer1.ReportSource = doc;
    }

    public DataSet GetData()
    {
        DataSet ds = new DataSet();
        TestItem testItem = new TestItem();
        string str1 = this.ProductSN;
        DateTime dt1 = this.TestTime;
        ds = testItem.GetTemplate_ARH9E(str1, dt1);
        return ds;
    }

    private void Page_Unload(object sender, EventArgs e)
    {
        doc.Dispose();
    }
}
